﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using QuanLyDuocPham.Controllers.QuanLyHeThong.DanhMuc;


namespace QuanLyDuocPham.View.QuanLyHeThong.DanhMuc
{
    /// <summary>
    /// Interaction logic for DONTHUOC_Edit_View.xaml
    /// </summary>
    public partial class DONTHUOC_Edit_View : Window
    {
        public DONTHUOC_Edit_View()
        {
            InitializeComponent();
        }
        public delegate void added();
        public added done; 
        string ma_dt;


        public string _ma_dt
        {
            set
            {
                ma_dt = value;
            }
        }
        DONTHUOC_Control dtctrl = new DONTHUOC_Control();
        BACSI_Control bsctrl = new BACSI_Control();
        NHOMDP_Control nhdpctrl = new NHOMDP_Control();
        DUOCPHAM_Control dpctrl = new DUOCPHAM_Control();
        DONTHUOC_CT_Control dtctctrl = new DONTHUOC_CT_Control();
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            dtctrl.loadForm_Edit(ma_dt, cmbBacSi, cmbNhom, txtTenToa, txtDien_Giai);
            dpctrl.loadData(listDP);
            dtctctrl.loadListBox_Edit(ma_dt, listDPinToa);
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            dtctrl.updateData(ma_dt, cmbBacSi, cmbNhom, txtTenToa, txtDien_Giai);
            dtctctrl.updateData(listDPinToa, ma_dt);
            if (done != null)
            {
                done();
            }
        }

        private void btnBack_Click(object sender, RoutedEventArgs e)
        {
            this.Close();

        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (listDP.SelectedItem == null)
                MessageBox.Show("Bạn chưa chọn dược phẩm nào để thêm vào danh sách!");
            else
                listDPinToa.Items.Add(listDP.SelectedItem);

        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            if (listDPinToa.SelectedItem == null)
                MessageBox.Show("Bạn chưa chọn dược phẩm nào để xóa khỏi danh sách!");
            else
                listDPinToa.Items.Remove(listDPinToa.SelectedItem);
        }

        private void txtSearch_TextChanged(object sender, TextChangedEventArgs e)
        {
            dpctrl.findData(txtSearch, listDP);
        }

        private void cmbBacSi_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void cmbNhom_KeyDown(object sender, KeyEventArgs e)
        {
            cmbNhom.IsDropDownOpen = true;
        }

        private void cmbBacSi_KeyDown(object sender, KeyEventArgs e)
        {
            cmbBacSi.IsDropDownOpen = true;

        }
    }
}
